package youcaihuaoa.weetop.com.vm.main

import android.app.Application
import api.UserServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.CustomListBean
import com.robot.base.model.WagesDetailBean
import com.robot.base.model.WagesProfileItemBean
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import me.goldze.mvvmhabit.http.BaseResponse
import youcaihuaoa.weetop.com.vm.apply.MyApplyViewModel

class WagesProfileViewModel(application: Application) : GLBaseViewModel(application) {

    val uiEvent = UIEvent()


    class UIEvent {

        val menuDataLiveEvent = SingleLiveEvent<MutableList<WagesProfileItemBean>>()

        val menu2DataLiveEvent = SingleLiveEvent<MutableList<WagesProfileItemBean>>()

    }

    fun initMenu(id: String) {
        showLoadingDialog()
        UserServiceFactory.wagesGenerateInfo(id)
            .subscribe(object : AbstractViewModelSubscriber<BaseResponse<WagesDetailBean>>(this) {
                override fun onNext(t: BaseResponse<WagesDetailBean>) {
                    dismissLoadingDialog()
                    t.data ?: return

                    val menu1 = mutableListOf(
                        WagesProfileItemBean().apply {
                            title = "姓名"
                            content = t.data.user_name ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "部门"
                            content = t.data.department_name ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "岗位"
                            content = t.data.job_name ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "工号"
                            content = t.data.job_number ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "电话"
                            content = t.data.phone ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "详细地址"
                            content = t.data.jg_data ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "基本工资"
                            content = t.data.user_jbgz_price ?: ""
                        }
                    )
                    val menu2 = mutableListOf(
                        WagesProfileItemBean().apply {
                            title = "迟到次数"
                            content = t.data.cd_num ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "早退次数"
                            content = t.data.zt_num ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "旷工次数"
                            content = t.data.kg_num ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "考勤应扣金额"
                            content = t.data.kqyg_price ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "全勤奖"
                            content = t.data.qqj_price ?: ""
                        }, WagesProfileItemBean().apply {
                            title = "绩效金额"
                            desc = "(手动填写)"
                            content = t.data.user_jxgz_price ?: ""
                        }
                    )
                    uiEvent.menuDataLiveEvent.postValue(menu1)
                    uiEvent.menu2DataLiveEvent.postValue(menu2)
                }
            })
    }
}